# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: w0rty <mawo97 at gmail.com>
# Contributor: Abdo Roig-Maranges <abdo.roig@gmail.com>

pkgname=glab
pkgver=1.28.1
pkgrel=1
pkgdesc='Cli tool to help work seamlessly with GitLab from the command line'
arch=(loong64 x86_64)
url="https://gitlab.com/gitlab-org/cli"
license=(MIT)
depends=(glibc)
makedepends=(go)
replaces=(gitlab-glab)
options=(!lto)
_archive="cli-v$pkgver"
source=("$url/-/archive/v$pkgver/$_archive.tar.gz")
sha256sums=('243a0f15e4400aab7b4d27ec71c6ae650bf782473c47520ffccd57af8d939c90')

build() {
	cd "$_archive"
	export CGO_CPPFLAGS="$CPPFLAGS"
	export CGO_CFLAGS="$CFLAGS"
	export CGO_CXXFLAGS="$CXXFLAGS"
	export CGO_LDFLAGS="$LDFLAGS"
	_builddate=${SOURCE_DATE_EPOCH=:$(date -u +%m/%d/%Y)}
	go build \
		-trimpath \
		-buildmode=pie \
		-ldflags "-linkmode=external -extldflags \"$LDFLAGS\" -X main.version=v$pkgver -X main.build=$_builddate -X main.usageMode=prod -s -w" \
		-mod=readonly \
		-modcacherw \
		-o "$pkgname" \
		./cmd/glab/main.go
	go run ./cmd/gen-docs/docs.go --manpage --path ./
	for s in bash fish zsh; do
		./$pkgname completion -s $s > $s.completions
	done
}

package() {
	cd "$_archive"
	install -Dm0644 -t "$pkgdir/usr/share/licenses/$pkgname/" LICENSE
	install -Dm0755 -t "$pkgdir/usr/bin/" "$pkgname"
	install -Dm0644 -t "$pkgdir/usr/share/man/man1/" "$pkgname"*.1
	install -Dm0644 bash.completions "$pkgdir/usr/share/bash-completion/completions/$pkgname"
	install -Dm0644 fish.completions "$pkgdir/usr/share/fish/vendor_completions.d/$pkgname.fish"
	install -Dm0644  zsh.completions "$pkgdir/usr/share/zsh/site-functions/_$pkgname"
}
